﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SqlCeViewer.Base;
using SqlCeViewer.CommonMethod;

namespace SqlCeViewer.UI
{
    public partial class SqlServer2Sdf : BaseSubForm
    {
        public SqlServer2Sdf()
        {
            InitializeComponent();


#if DEBUG
            this.simpleButton2.Visible = true;
#else
            this.simpleButton2.Visible = false;
#endif
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            string server = txtServername.Text;
            string database = this.txtDbName.Text;
            string username = this.txtUsername.Text;
            string pwd = passwordBox1.Text;

            if (string.IsNullOrEmpty(server) || string.IsNullOrEmpty(database)
                || string.IsNullOrEmpty(username))
            {
                MessageBox.Show("Please input each element");
                return;
            }
            string sdfFile = string.Empty;

            SaveFileDialog sf = new SaveFileDialog();
            sf.Filter = GlobalInfo.SQLCE_FILE_FILTER;
            if (sf.ShowDialog() == DialogResult.OK)
            {
                sdfFile = sf.FileName;
            }
            else
            {
                return;
            }

            bool isNeedCopyData = false;
            if (this.checkEdit1.Checked)
            {
                isNeedCopyData = true;
            }

            if (CommonUtil.SyncDataFromSqlServerToSqlCE(server, database, username, pwd, sdfFile, isNeedCopyData))
            {
                MessageBox.Show(String.Format("Sync data from \r\n{0} \r\nto \r\n{1} \r\nSuccessful", database, sdfFile));
            }
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            this.txtServername.Text = "localhost";
            this.txtDbName.Text = "test";
            this.txtUsername.Text = "sa";
            passwordBox1.Text = "test";
        }
    }
}